package cn.maven.main;

import cn.maven.module.Table;
import cn.maven.utils.TableUtil;
import freemarker.template.TemplateException;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AddJsHandler {

    private Generator generator = new Generator();

    public void exectue() throws IOException, TemplateException {
        //获取table对应的实例
        List<Table> tableList = TableUtil.getTable();
        Map<String, Object> param = new HashMap<>();
        //设置模板路径
        String templatePath = this.getClass().getClassLoader().getResource("").getPath();
        System.out.println(templatePath);
        String savePath = "F:\\IdeaWorkSpace\\adminTemp\\src\\main\\webapp\\static\\js";


        for (Table table : tableList) {
            //创建目录
            String dirName =savePath+"\\"+table.getLowerClassName();
            MainHandler.createDir(dirName);
            param.put("table", table);
            generator.init(templatePath);
            generator.process("addJs.ftl", dirName + "/"+ "add.js", param);
        }
    }

  /*  public static void main(String[] args) throws IOException, TemplateException {
        AddJsHandler moduleHandler = new AddJsHandler();
        moduleHandler.exectue();
    }*/
}
